package cn.edu.zju.qsc.rouchseg.segment;

import java.util.ArrayList;
import java.util.List;

public class ChineseSegment {
	private String dicFilename = "cn/edu/zju/qsc/rouchseg/dic/main.dic";
	
	private Splitter splitter;
	private DefaultSeg segment;
	
	public ChineseSegment() {
		this.segment = new DefaultSeg(this.dicFilename);
		this.splitter = new Splitter();
	}
	
	public List<String> cut(String sentence) {
		List<String> result = new ArrayList<String>();
		List<String> sentences = this.splitter.split(sentence);
		String txt;
		for (int i = 0; i < sentences.size(); i++) {
			txt = sentences.get(i);
			if (txt.isEmpty()) {
				continue;
			}
			/* 不对拉丁字符分词 */
			if (txt.length() <= 3 || this.splitter.latinPattern.matcher(txt).find()) {
				result.add(txt);
			} else {
				result.addAll(this.segment.cut(txt));
			}
		}
		return result;
	}
}
